<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item v-show="false" label="主键">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="等级" prop="level">
            <el-input v-model="form.level" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="等级名称" prop="levalName">
            <el-input v-model="form.levalName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="流水奖励" prop="waterAward">
            <el-input v-model="form.waterAward" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="团队奖励" prop="teamAward">
            <el-input v-model="form.teamAward" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户直接推广人数" prop="userPopu">
            <el-input v-model="form.userPopu" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="团队人数" prop="teamPeople">
            <el-input v-model="form.teamPeople" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择用户类型">
              <el-option value="0" label="未启用" />
              <el-option value="1" label="启用" />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="主键" />
        <el-table-column v-if="columns.visible('level')" prop="level" label="等级" />
        <el-table-column v-if="columns.visible('levalName')" prop="levalName" label="等级名称" />
        <el-table-column v-if="columns.visible('waterAward')" prop="waterAward" label="流水奖励" />
        <el-table-column v-if="columns.visible('teamAward')" prop="teamAward" label="团队奖励" />
        <el-table-column v-if="columns.visible('userPopu')" prop="userPopu" label="用户直接推广人数" />
        <el-table-column v-if="columns.visible('teamPeople')" prop="teamPeople" label="团队人数" />
        <el-table-column v-if="columns.visible('status')" prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.status == 0?"未启用":"启用" }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','mhzMenberLevel:edit','mhzMenberLevel:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMhzMenberLevel from '@/api/user/mhzMemberLevel'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '会员等级', url: 'api/mhzMenberLevel', sort: 'id,desc', crudMethod: { ...crudMhzMenberLevel }})
const defaultForm = { id: null, level: null, levalName: null, waterAward: null, teamAward: null, userPopu: null, teamPeople: null, status: null }
export default {
  name: 'MhzMenberLevel',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'mhzMenberLevel:add'],
        edit: ['admin', 'mhzMenberLevel:edit'],
        del: ['admin', 'mhzMenberLevel:del']
      },
      rules: {
        level: [
          { required: true, message: '等级不能为空', trigger: 'blur' }
        ],
        levalName: [
          { required: true, message: '等级名称不能为空', trigger: 'blur' }
        ],
        waterAward: [
          { required: true, message: '流水奖励不能为空', trigger: 'blur' }
        ],
        teamAward: [
          { required: true, message: '团队奖励不能为空', trigger: 'blur' }
        ],
        userPopu: [
          { required: true, message: '用户直接推广人数不能为空', trigger: 'blur' }
        ],
        teamPeople: [
          { required: true, message: '团队人数不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'level', display_name: '等级' },
        { key: 'levalName', display_name: '等级名称' },
        { key: 'status', display_name: '状态' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
